home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Broadcaster
/
ZBroadcaster.inc
< prev
next >
Wrap
Text File
|
1997-08-31
|
2KB
|
76 lines
/*
* File: ZBroadcaster.inc
* Summary: Mixin class allowing an object to broadcast to one or more listeners.
* Written by: Jesse Jones
*
* Copyright ゥ 1996-1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <2> 8/30/97 JDJ Broadcast no longer stuffs message
* in a member.
* <1> 1/17/96 JDJ Created.
*/
#include <ZDebug.h>
//---------------------------------------------------------------
//
// MBroadcaster::~MBroadcaster
//
//---------------------------------------------------------------
template <class MESSAGE>
MBroadcaster<MESSAGE>::~MBroadcaster()
{
}
//---------------------------------------------------------------
//
// MBroadcaster::MBroadcaster ()
//
//---------------------------------------------------------------
template <class MESSAGE>
MBroadcaster<MESSAGE>::MBroadcaster()
{
}
//---------------------------------------------------------------
//
// MBroadcaster::Broadcast
//
//---------------------------------------------------------------
template <class MESSAGE>
void MBroadcaster<MESSAGE>::Broadcast(const MESSAGE& message) const
{
this->DoBroadcasting(&message);
}
//---------------------------------------------------------------
//
// MBroadcaster::DoBroadcast
//
// All of this casting is kind of gross, but it allows us to put
// all the list code in a non-template base class. This can really
// add up since broadcasters are often used with weird types.
//
//---------------------------------------------------------------
template <class MESSAGE>
void MBroadcaster<MESSAGE>::DoBroadcast(MBaseListener* theListener, const void* theMessage) const
{
MListener<MESSAGE>* listener = dynamic_cast<MListener<MESSAGE>*>(theListener);
ASSERT(theListener != nil);
ASSERT(listener != nil);
const MESSAGE* message = reinterpret_cast<const MESSAGE*>(theMessage);
ASSERT(message != nil);
listener->OnBroadcast(*message);
}